package com.webinsky.publish.persist.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.type.JdbcType;

import com.webinsky.publish.persist.entity.BookPublish;

public interface BookPublishMapper {
	@Insert({
		"insert into `publish` (book_id, file_name, version, publish_date, publish_user_id, language)",
		"values (#{siteId,jdbcType=INTEGER}, #{fileName,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, now(), #{publishUserId,jdbcType=INTEGER}, #{language,jdbcType=VARCHAR})"
	})
	@SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
	int insert(BookPublish record);
	
	@Select({
	    "select",
	    "id, site_id, file_name, version, publish_date, publish_user_id, language",
	    "from `publish`",
	    "where site_id = #{siteId, jdbcType=INTEGER} and language = #{lang, jdbcType=VARCHAR}"
	})
	@Results({
	    @Result(column="id", property="id", jdbcType=JdbcType.INTEGER),
	    @Result(column="site_id", property="siteId", jdbcType=JdbcType.INTEGER),
	    @Result(column="file_name", property="fileName", jdbcType=JdbcType.VARCHAR),
	    @Result(column="version", property="version", jdbcType=JdbcType.INTEGER),
	    @Result(column="publish_date", property="publishDate", jdbcType=JdbcType.TIMESTAMP),
	    @Result(column="publish_user_id", property="publishUserId", jdbcType=JdbcType.INTEGER),
	    @Result(column="language", property="language", jdbcType=JdbcType.VARCHAR)
	})
	List<BookPublish> selectByBookIdAndLanguage(@Param("siteId")int siteId, @Param("lang")String lang);
}
